/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { PureComponent } from 'react';
import { Table } from 'antd';
import DragTable from '@/components/DragTable';

export default class Tables extends PureComponent {
  state = {};

  paginationChange = e => {
    this.props.paginationChange(e);
  };

  render() {
    const {
      dataSource,
      columns,
      bordered = true,
      loading,
      id,
      pagination = {},
      paginationChange,
      style,
      ...rest
    } = this.props;
    const { size = 20, count, page = 1 } = pagination;
    let paginationProp = {
      showQuickJumper: true,
      pageSize: size,
      total: count,
      defaultCurrent: 1,
      current: page,
      hideOnSinglePage: true,
      showTotal: () => `共 ${Math.ceil(count / size)} 页`,
      itemRender: (current, type, originalElement) => {
        if (type === 'prev') {
          return <a>上一页</a>;
        }
        if (type === 'next') {
          return <a>下一页</a>;
        }
        return originalElement;
      },
    };
    paginationProp = paginationChange
      ? { ...paginationProp, onChange: this.paginationChange }
      : paginationProp;
    return (
      <DragTable>
        <Table
          // locale={{ emptyText: '暂无数据' }}
          bordered={bordered}
          loading={loading}
          rowKey={id || 'id'}
          pagination={paginationProp}
          columns={columns}
          dataSource={dataSource}
          style={style}
          {...rest}
        />
      </DragTable>
    );
  }
}
